package com.mqtt;

import android.content.Context;

import com.mqtt.dao.MQTTBean;
import com.mqtt.mqtt.MqttConnectionBean;
import com.mqtt.util.SharePreferenceUtil;

import org.litepal.LitePal;
import org.litepal.LitePalApplication;

import java.util.List;

import static com.mqtt.Configure.CURRENT_IP;

/**
 * @Author xiaowen
 * @Email xiaowen.wxf@google.com
 * @Date 2018/10/15 .
 * @Description This is MqttApplication.
 */

public class MqttApplication extends LitePalApplication {

    public static List<MQTTBean> sMQTTListBean;
    public static Context mContext ;
    public static MqttConnectionBean mMqttConnectionBean;
    private MqttConnectionBean mTmpMqttBean;

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;
//        sMQTTListBean = LitePal.findAll(MQTTBean.class);
        String ip = SharePreferenceUtil.getString(this, Configure.CURRENT_IP,"ABC");
        sMQTTListBean = LitePal.where("broker_ip = ?",ip).find(MQTTBean.class);
        List<MqttConnectionBean> mqttConnectionBeans = LitePal.where("broker_ip = ?", ip).find(MqttConnectionBean.class);
        try {
            mMqttConnectionBean = mqttConnectionBeans.get(mqttConnectionBeans.size()-1);
        } catch (Exception e) {

        }
    }

    public MqttConnectionBean getmTmpMqttBean() {
        return mTmpMqttBean;
    }

    public void setmTmpMqttBean(MqttConnectionBean mTmpMqttBean) {
        this.mTmpMqttBean = mTmpMqttBean;
    }
}
